#!/usr/bin/python
#coding:utf8
'''
Mediator
'''

class ChatMediator:
    def __init__(self,group_name):
        self._users = []
        self.group_name = group_name
    def addUser(self, user):
        self._users.append(user)
    def sendMessage(self, message, user):
        for u in self._users:
            if u != user:
                u.receiveMessage(self.group_name+f"({u.name})"+">>>From "+user.name+": "+message)
            else:
                u.receiveMessage(self.group_name+f"({u.name})"+">>> "+message)
class User:
    def __init__(self, name, mediator):
        self.name = name
        self.mediator = mediator
    def sendMessage(self, message):
        self.mediator.sendMessage(message, self)

    def receiveMessage(self, message):
        print(message)

if __name__ == '__main__':
    mediator = ChatMediator("工作群1")
    mingming = User("小明", mediator)
    pangpang = User("胖虎", mediator)
    wangcai = User("旺财", mediator)
    mediator.addUser(mingming)
    mediator.addUser(pangpang)
    mediator.addUser(wangcai)
    mingming.sendMessage("开工!")
    pangpang.sendMessage("收到!")
    